﻿#region License
/*
 *CopyRight (c) By Denuvead All Rights Reserved
 *CreateDate:
 *Info:
 */
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace PriErp.Tools.Extensions
{
    /// <summary>
    /// 扩展类
    /// </summary>
    public static partial class PriErpExtension
    {
        /// <summary>
        /// 读取InnerText(类型为空时返回null)
        /// </summary>
        /// <param name="el">需要读取的XmlNode</param>
        /// <returns>返回String</returns>
        static public string InnerTextOrNull(this XmlNode node)
        {
            return node.InnerTextOrDefault(null);
        }

        /// <summary>
        /// 读取InnerText(类型为空时返回String.Empty)
        /// </summary>
        /// <param name="el">需要读取的XmlNode</param>
        /// <returns>返回String</returns>
        static public string InnerTextOrEmpty(this XmlNode node)
        {
            return node.InnerTextOrDefault(string.Empty);
        }

        /// <summary>
        /// 读取InnerText(类型为空时返回默认值)
        /// </summary>
        /// <param name="node">需要读取的XmlNode</param>
        /// <param name="sVal">默认值</param>
        /// <returns>返回String</returns>
        static public string InnerTextOrDefault(this XmlNode node, string sVal)
        {
            return node == null ? sVal : node.InnerText;
        }

        /// <summary>
        /// 读取Value(类型为空时返回null)
        /// </summary>
        /// <param name="el">需要读取的XmlNode</param>
        /// <returns>返回String</returns>
        static public string ValueOrNull(this XmlNode node)
        {
            return node.ValueOrDefault(null);
        }

        /// <summary>
        /// 读取Value(类型为空时返回String.Empty)
        /// </summary>
        /// <param name="el">需要读取的XmlNode</param>
        /// <returns>返回String</returns>
        static public string ValueOrEmpty(this XmlNode node)
        {
            return node.ValueOrDefault(string.Empty);
        }

        /// <summary>
        /// 读取Value(类型为空时返回默认值)
        /// </summary>
        /// <param name="node">需要读取的XmlNode</param>
        /// <param name="sVal">默认值</param>
        /// <returns>返回String</returns>
        static public string ValueOrDefault(this XmlNode node, string sVal)
        {
            return node == null ? sVal : node.Value;
        }
    }
}
